<template>
  <div class="loading">
    <h1>登录页</h1>
    <el-form ref="form" class="from" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.pwd"></el-input>
      </el-form-item>
      <el-form-item class="anniu">
        <el-button type="primary" @click="onSubmit">登录</el-button>
        <el-button @click="qingk">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Message } from "element-ui";
import { isLoading } from "@api";
export default {
  data() {
    return {
      form: {
        username: "",
        pwd: "",
      },
    };
  },
  methods: {
    onSubmit() {
      isLoading(this.form).then((res) => {
        if (res.data.code === 200) {
          localStorage.setItem("token", res.data.data.token);
          localStorage.setItem(
            "userinfo",
            JSON.stringify(res.data.data.userinfo)
          );
          Message.success({
            showClose: true,
            message: "登录成功",
            type: "success",
            duration:2000,
            onClose:()=>{
              this.$router.push('/app/dashboard')
            }
          }
         
          );
        }
      });
    },
    qingk() {
      this.form = {};
    },
  },
};
</script>

<style lang="scss" scoped>
.loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.el-form {
  width: 600px;
}
.loading h1 {
  text-align: center;
}
.anniu {
  margin-left: 180px;
}
</style>